//
//  PersonalViewController.m
//  Korea
//
//  Created by 崔剑 on 15/8/24.
//  Copyright (c) 2015年 KoreaGo. All rights reserved.
//

#import "PersonalViewController.h"
#import "SetUpViewController.h"
#import "AlterInfoController.h"
#import "HeaderViewController.h"
#import "Header.h"
#import "PersonalCell.h" 
#import "PersonalInfoCell.h"
#import "LoginViewController.h"

@interface PersonalViewController () <UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) UITableView *personalTableView;
@property (nonatomic, strong) NSMutableArray *personInfoArr;

@end

@implementation PersonalViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"我";
    self.view.backgroundColor = [UIColor colorWithRGB:0xf3f4f8 alpha:1];
    
    
    

    self.personalTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, self.view.height / 5 + 270) style:UITableViewStylePlain];
    self.personalTableView.backgroundColor = [UIColor colorWithRGB:0xf3f4f8 alpha:1];
    
    // 隐藏滑动条
    self.personalTableView.showsVerticalScrollIndicator = NO;
    self.personalTableView.scrollEnabled = NO;
    self.personalTableView.delegate = self;
    self.personalTableView.dataSource = self;
    [self.view addSubview:self.personalTableView];
    // 自适应屏幕
    self.edgesForExtendedLayout = UIRectEdgeNone;
    // 注册重用池
    [self.personalTableView registerClass:[PersonalCell class] forCellReuseIdentifier:@"personalReuse"];

    [self.personalTableView registerClass:[PersonalInfoCell class] forCellReuseIdentifier:@"personalInfoReuse"];
    
    self.personInfoArr = [NSMutableArray arrayWithObjects:@"   联系电话", @"   邮箱", @"   生日", @"   地区", nil];
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        return self.view.height / 5;
    }
    
    return 50;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 1;
    } if (section == 1) {
        return 4;
    }
    
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return 0;
    }
    
    return 10;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        
        PersonalCell *cell = [tableView dequeueReusableCellWithIdentifier:@"personalReuse"];
        // 点击cell不变色
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
    
    PersonalInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"personalInfoReuse"];
    // 点击cell不变色
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (indexPath.section == 1 && indexPath.row == 0) {
        cell.listLabel.text = self.personInfoArr[0];
//        cell.infoLabel.text = @"123512351";
    } if (indexPath.section == 1 && indexPath.row == 1) {
        cell.listLabel.text = self.personInfoArr[1];
//        cell.infoLabel.text = @"123512351@qq.com";
    } if (indexPath.section == 1 && indexPath.row == 2) {
        cell.listLabel.text = self.personInfoArr[2];
//        cell.infoLabel.text = @"上海";
    } if (indexPath.section == 1 && indexPath.row == 3) {
        cell.listLabel.text = self.personInfoArr[3];
//        cell.infoLabel.text = @"ASFASF嘎嘎嘎是打工哈as的";
    } if (indexPath.section == 2) {
        cell.listLabel.text = @"   设置";
        UIImageView *nextImageView = [[UIImageView alloc] initWithFrame:CGRectMake(340, 12.5, 25, 25)];
        [nextImageView setImage:[UIImage imageNamed:@"next@2x.png"]];
        [cell addSubview:nextImageView];
    }
    
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
//    NSString *token = [user valueForKey:@"userInfo"];
//    if (token == NULL) {
//       
//    dispatch_async(dispatch_get_main_queue(), ^{
//        LoginViewController *login = [[LoginViewController alloc] init];
//        login.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
//        [self presentViewController:login animated:YES completion:nil];
//    });
//    }
//    
//    
//    else{


    if (indexPath.section == 0) {
        HeaderViewController *headerVC = [[HeaderViewController alloc] init];
        [self.navigationController pushViewController:headerVC animated:YES];
        
    }
    
    if (indexPath.section == 1) {
        AlterInfoController *alterInfoVC = [[AlterInfoController alloc] init];
        [self.navigationController pushViewController:alterInfoVC animated:YES];
        NSString *str = self.personInfoArr[indexPath.row];
        alterInfoVC.titleName = str;

    }
    
    if (indexPath.section == 2) {
        SetUpViewController *setUpVC = [[SetUpViewController alloc] init];
        [self.navigationController pushViewController:setUpVC animated:YES];
        
    }
//    }
    
}

- (void)viewWillAppear:(BOOL)animated
{
    
    [self.personalTableView reloadData];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
